package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.web.domain.AjaxResult;
import com.sikaryofficial.system.api.RemoteProfileService;
import com.sikaryofficial.system.api.domain.SysUser;
import com.sikaryofficial.system.api.model.SysUserEmailReq;
import com.sikaryofficial.system.api.model.SysUserNickNameReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * Profile服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteProfileFallbackFactory implements FallbackFactory<RemoteProfileService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteProfileFallbackFactory.class);

    @Override
    public RemoteProfileService create(Throwable throwable) {
        log.error("Profile服务调用失败:{}", throwable.getMessage());
        return new RemoteProfileService() {
            /**
             * 个人背景图上传
             *
             * @param file     文件信息
             * @param deviceId
             * @param channel
             * @return 结果
             */
            @Override
            public AjaxResult updateBackImg(MultipartFile file, String deviceId, String channel) {
                return AjaxResult.error("updateBackImg fail:" + throwable.getMessage());
            }

            /**
             * 头像上传-更新
             *
             * @param file     文件信息
             * @param deviceId
             * @param channel
             * @return 结果
             */
            @Override
            public AjaxResult updateAvatar(MultipartFile file, String deviceId, String channel) {
                return AjaxResult.error("updateAvatar fail:" + throwable.getMessage());
            }

            /**
             * 邮箱更新
             *
             * @param req
             * @param deviceId
             * @param channel
             * @return
             */
            @Override
            public AjaxResult updateEmail(SysUserEmailReq req, String deviceId, String channel) {
                return AjaxResult.error("updateEmail fail:" + throwable.getMessage());
            }

            /**
             * 修改昵称
             *
             * @param req
             * @return
             */
            @Override
            public AjaxResult updateNickName(SysUserNickNameReq req) {
                return AjaxResult.error("updateNickName fail:" + throwable.getMessage());
            }

            /**
             * 个人资料更新
             *
             * @param user
             * @param deviceId
             * @param channel
             * @return
             */
            @Override
            public AjaxResult updateProfile(SysUser user, String deviceId, String channel) {
                return AjaxResult.error("updateProfile fail:" + throwable.getMessage());
            }
        };
    }
}
